﻿/*********************************************************************
 * @file       dayly_block.cpp
 * @brief      日程小组件的类
 * @details    基于ui文件运行
 * @author     南樟(a2169272059@163.com)
 * @date       2025-2-10
 * @version    1.0.0
 * @copyright  a2169272059@163.com
 *********************************************************************/
#include "dayly_block.h"
#include "ui_dayly_block.h"
#include "create_dayly.h"
#include "mainwindow.h"
/**
 * @brief dayly_block::dayly_block 日程小组件的构造函数
 * @param parent 父节点
 * @param id 对应在数据库中的id
 * @param time0 该日程的开始时间
 * @param time1 该日程的结束时间
 * @param noteText 该日程的备注
 * @param addDay 该日程的结束时间相对于现在是多少天后
 * @param preDay 该日程的开始时间相对于现在是多少天前
 */
dayly_block::dayly_block(QWidget *parent,const int &id,const QString time0,
                         const QString time1,const QString noteText,
                         const int &addDay,const int &preDay)
    : QWidget(parent)
    , ui(new Ui::dayly_block)
    ,m_id(id)
{
    ui->setupUi(this);
    ui->time0->setText(time0);
    ui->time1->setText(time1);
    ui->noteText->setText(noteText);
    if(addDay==0){
        ui->addDay->setText("");
    }else{
        ui->addDay->setText(QString::asprintf("+%d天",addDay));
    }
    if(preDay==0){
        ui->preDay->setText("");
    }else{
        ui->preDay->setText(QString::asprintf("-%d天",preDay));
    }
}
/**
 * @brief dayly_block::~dayly_block 日程小组件的析构函数
 */
dayly_block::~dayly_block()
{
    delete ui;
}
/**
 * @brief dayly_block::on_editBtn_clicked [编辑]按钮的逻辑
 */
void dayly_block::on_editBtn_clicked()
{
    auto tmpWidget = new create_dayly(this);
    tmpWidget->change2Edit(m_id);
    connect(tmpWidget,&create_dayly::back2dayly,this,[this,tmpWidget](){
        g_mainWidget->setCurrentIndex(MainWindow::index_day);
        tmpWidget->deleteLater();
    });
    g_mainWidget->addWidget(tmpWidget);
    g_mainWidget->setCurrentWidget(tmpWidget);
}

